package com.marcelolog.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.marcelolog.dao.LoggerDAO;
import com.marcelolog.entity.Log;
import com.marcelolog.factory.ConnFactory;

public class LoggerDAOImpl implements LoggerDAO {

	
	private static String SQL_INSERT = 
			" INSERT INTO " +
			" tbl_log(id_usuario, data_hora_log, nome_objeto, acao, descricao) " +
			" VALUES " +
			" ( ? , SYSDATE(), ? , ? , ? ) ";
	
	@Override
	public void salvarLog(Log log) throws Exception {

		Connection conn = new ConnFactory().getConnection();
		PreparedStatement pstmt = conn.prepareStatement(SQL_INSERT);
		
		try {
			
			pstmt.setInt(1, log.getIdUsuario());
			pstmt.setString(2, log.getNomeObjeto());
			pstmt.setString(3, log.getAcao());
			pstmt.setString(4, log.getDescricao());
			
			pstmt.execute();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
 
	}

}
